package com.headline.common;

import javax.servlet.http.HttpServletRequest;
import java.sql.Date;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * Created by Administrator on 2016/10/31.
 */
public class Common {

    public static void ShowMessage(Object o) {
        System.out.println(o);
    }

    /**
     * util.data转sql.date
     * 2016/9/14  11:13
     */
    public static java.sql.Date GetSqlDate(String pubDate) throws ParseException {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date d = new java.util.Date();
        if (!pubDate.equals("")) {
            d = sdf.parse(pubDate);
        }
        java.sql.Date date = new java.sql.Date(d.getTime());
        return date;
    }

    /**
     * util.data转Timestamp
     * 2016/10/31  17:19
     */

    public static Timestamp GetTimeStamp(String strDate) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        format.setLenient(false);
        try {
            Timestamp ts = new Timestamp(format.parse(strDate).getTime());
            return ts;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }


    /**
     * @param id
     * @return OpenScheme
     */
    public static String getOpenScheme(long id,String title) {
        String url = "http://123.206.6.130:8080/wzheadline/article/show/%s";
        url = String.format(url, id);
        String strResult = "wzsdk://wzarticle?url=%s&title=%s&share=%s&sharetitle=%s&content=%s&shareurl=%s";
        strResult = String.format(strResult,
                StringUtil.EncodeUTF8Value(url),
                StringUtil.EncodeUTF8Value(title),1,
                StringUtil.EncodeUTF8Value(title),
                StringUtil.EncodeUTF8Value(title),
                StringUtil.EncodeUTF8Value(url));
        return strResult;
    }

}

